home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------
- //
- // SuperCode (c) 1996 by T.Kühn
- //
- // Programmiersprache: ANSI-C
- // Projektstart: 12.7.95
- //
- // Modul: Super-Code
- //
- //-------------------------------------
-
- #include <pragma/exec_lib.h>
- #include <pragma/graphics_lib.h>
- #include <pragma/intuition_lib.h>
- #include <pragma/gadtools_lib.h>
- #include <pragma/layers_lib.h>
- #include <pragma/dos_lib.h>
-
- #include <intuition/gadgetclass.h>
- #include <intuition/imageclass.h>
-
- #include "struct.h"
-
- //-------------------------------------
-
- struct Window *supercode_window=0;
-
- struct box
- {
- LONG x;
- LONG y;
- LONG w;
- LONG h;
- LONG xs;
- LONG w1,h1;
- LONG max;
- };
-
- struct box field;
- struct box value;
- struct box pal;
-
- LONG drag_color=0;
-
- struct Gadget *gadget_1st,
- *gadget_new=0,
- *gadget_solve=0,
- *gadget_name=0,
- *gadget_time=0,
- *gadget_comb=0,
- *gadget_score=0;
-
- enum gadget_id
- {
- ID_NONE,
- ID_NEW,
- ID_SOLVE,
- ID_SCORE,
- ID_COMP,
- };
-
- struct RastPort rport_bg;
- struct RastPort rport_ob;
-
- ULONG icon_w=10;
- ULONG icon_h=10;
-
- UWORD *color_tabl=0;
- UBYTE *color_stat=0;
-
- enum status
- {
- STATUS_NONE,
- STATUS_IN,
- STATUS_OUT,
- STATUS_END,
- };
-
- UWORD words[]= {0x9F9F,0x9F9F,0xF9F9,0xF9F9,0};
-
- #define display_mode (prg_prefs->game.display)
-
- char supercode_version[]="1.00";
- char programmer_name[]="Tilo Kuehn @1996";
-
-
- //-------------------------------------
- void draw_thinborder(struct RastPort *rp,LONG x,LONG y, LONG w, LONG h,ULONG border)
- {
- LONG c1,c2,s=0;
-
- w--;
- h--;
-
- if (w>1 && h>1)
- {
- if (border)
- {
- c1=Scrn.DrawInfo->dri_Pens[SHADOWPEN];
- c2=Scrn.DrawInfo->dri_Pens[SHINEPEN];
- }
- else
- {
- c1=Scrn.DrawInfo->dri_Pens[SHINEPEN];
- c2=Scrn.DrawInfo->dri_Pens[SHADOWPEN];
- }
-
- SetAPen(rp,c1);
- Move(rp,x,y+h-1);
- Draw(rp,x,y);
- Draw(rp,x+w,y);
-
- SetAPen(rp,c2);
- Draw(rp,x+w,y+h);
- Draw(rp,x,y+h);
- }
- }
- //-------------------------------------
- void draw_thinborderfield(struct RastPort *rp,LONG c,LONG x,LONG y, LONG w, LONG h,ULONG border)
- {
- LONG s;
- LONG ca,cb;
-
- draw_thinborder(rp,x,y,w,h,border);
-
- w--;
- h--;
-
- s=color_stat[c];
- ca=(color_tabl[c] >> 8 ) & 0xff;
- cb=(color_tabl[c] & 0xff);
-
- if (display_mode==DISPLAY_COLORS)
- {
- if (w>2 && h>2)
- {
- SetAPen(rp,ca);
- if (ca==cb)
- {
- rp->AreaPtrn=0;
- rp->AreaPtSz=0;
- }
- else
- {
- rp->AreaPtrn=words;
- rp->AreaPtSz=2;
- SetBPen(rp,cb);
- }
- RectFill(rp,x+2,y+2,x+w-2,y+h-2);
- }
-
- if (s>0)
- {
- ULONG f,g;
-
- g=GetRGB4(Scrn.Scrn->ViewPort.ColorMap,ca);
- f= (g&0xf) + ((g>>4) &0xf)*2 + ((g>>8) &0xf)*2;
- if (f < 25)
- {
- f=Scrn.DrawInfo->dri_Pens[SHINEPEN];
- }
- else
- {
- f=Scrn.DrawInfo->dri_Pens[SHADOWPEN];
- }
-
- SetAPen(rp,f);
- if (s==STATUS_OUT)
- {
- ULONG wk=(w+2)/3;
- ULONG hk=(h+2)/3;
-
- Move(rp,x+wk,y+hk);
- Draw(rp,x+w-wk,y+h-hk);
- Move(rp,x+w-wk,y+hk);
- Draw(rp,x+wk,y+h-hk);
- }
- else if (s==STATUS_IN)
- {
- ULONG wk=(w+2)/3;
- ULONG hk=(h+2)/3;
-
- DrawEllipse(rp,x+w/2,y+h/2,wk/2,hk/2);
- }
- }
- }
- else if (display_mode==DISPLAY_LETTER)
- {
- UBYTE txt[2];
- UWORD *pens=Scrn.DrawInfo->dri_Pens;
- UWORD f,b;
-
- rp->AreaPtrn=0;
- rp->AreaPtSz=0;
-
- if (c!=0)
- {
- if (s==STATUS_OUT)
- {
- f=pens[TEXTPEN];
- b=pens[BACKGROUNDPEN];
- }
- else if (s==STATUS_IN)
- {
- f=pens[HIGHLIGHTTEXTPEN];
- b=pens[FILLPEN];
- }
- else
- {
- f=pens[TEXTPEN];
- b=pens[FILLPEN];
- }
- SetAPen(rp,b);
- RectFill(rp,x+2,y+2,x+w-2,y+h-2);
-
- txt[0]='A'+c-1;
- txt[1]=0;
-
- Txt_PrintFit(rp,txt,1,x+2,y+2,w-2,h-2,f,b,BOX_CENTER);
- }
- else
- {
- SetAPen(rp,pens[BACKGROUNDPEN]);
- RectFill(rp,x+2,y+2,x+w-2,y+h-2);
- }
- }
- }
- //-------------------------------------
- void draw_thinbordervalue(struct RastPort *rp,LONG c,LONG x,LONG y, LONG w, LONG h,ULONG border)
- {
- LONG s=0;
- LONG f;
-
- draw_thinborder(rp,x,y,w,h,border);
-
- w--;
- h--;
-
- rp->AreaPtrn=0;
- rp->AreaPtSz=0;
-
- switch(c)
- {
- case BLACK: f=Scrn.DrawInfo->dri_Pens[SHADOWPEN];break;
- case WHITE: f=Scrn.DrawInfo->dri_Pens[SHINEPEN];break;
- default: f=Scrn.DrawInfo->dri_Pens[BACKGROUNDPEN];break;
- }
-
- SetAPen(rp,f);
- RectFill(rp,x+2,y+2,x+w-2,y+h-2);
-
- }
- //-------------------------------------
-
- #define LIBV39 (39)
- //-------------------------------------
- struct BitMap *tkAllocBitMap(ULONG width,ULONG height,ULONG depth,ULONG flags,struct BitMap *like_bitmap)
- {
- struct BitMap *bitmap=0;
-
- if (GfxBase->lib_Version>=LIBV39)
- {
- bitmap=AllocBitMap(width,height,depth,flags,like_bitmap);
- }
- else
- {
- ULONG t;
-
- bitmap=(struct BitMap*)Memory_Alloc(sizeof(struct BitMap));
-
- InitBitMap(bitmap,depth,width,height);
-
- for (t=0;t<depth;t++)
- {
- bitmap->Planes[t]=AllocRaster(width,height);
- if (bitmap->Planes[t]) BltClear(bitmap->Planes[t],(bitmap->BytesPerRow<<16|bitmap->Rows),0x3);
- }
- }
-
- return bitmap;
- }
- //-------------------------------------
- void tkFreeBitMap(struct BitMap *bitmap)
- {
- if (GfxBase->lib_Version>=LIBV39)
- {
- FreeBitMap(bitmap);
- }
- else
- {
- ULONG t;
-
- for (t=0;t<8;t++)
- {
- if (bitmap->Planes[t])
- {
- FreeRaster(bitmap->Planes[t],bitmap->BytesPerRow*8,bitmap->Rows);
- }
- }
- Memory_Free((UBYTE**)&bitmap);
- }
- }
- //-------------------------------------
- ULONG tkGetBitMapAttr(struct BitMap *bitmap,ULONG attr)
- {
- ULONG res=0;
-
- if (GfxBase->lib_Version>=LIBV39)
- {
- res=GetBitMapAttr(bitmap,attr);
- }
- else
- {
- switch(attr)
- {
- case BMA_HEIGHT:
- res=bitmap->Rows;
- break;
- case BMA_WIDTH:
- res=bitmap->BytesPerRow*8;
- break;
- case BMA_DEPTH:
- res=bitmap->Depth;
- break;
- case BMA_FLAGS:
- res=bitmap->Flags;
- break;
- }
- }
-
- return res;
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void icon_drag(ULONG c,ULONG *x,ULONG *y)
- {
- struct Window *window=supercode_window;
- struct BitMap *bitmap_sc=0;
- struct BitMap *bitmap_ob=0;
- struct BitMap *bitmap_bg=0;
- struct Screen *screen=window->WScreen;
- struct RastPort *rport_wi=window->RPort;
- LONG depth;
- LONG w=icon_w;
- LONG h=icon_h;
- LONG x1=(*x)-w/2;
- LONG y1=(*y)-h/2;
- LONG x2=x1;
- LONG y2=y1;
- LONG mask=0xff;
-
- struct IntuiMessage *msg;
- LONG code=0,clas=0;
-
- if (screen)
- {
- // LockLayerInfo(&screen->LayerInfo);
-
- window->Flags|=WFLG_RMBTRAP;
-
- bitmap_sc=screen->RastPort.BitMap;
- if (bitmap_sc)
- {
- depth=tkGetBitMapAttr(bitmap_sc,BMA_DEPTH);
-
- bitmap_ob=tkAllocBitMap(w,h+2,depth,BMF_CLEAR|BMF_INTERLEAVED,bitmap_sc);
- bitmap_bg=tkAllocBitMap(w,h+2,depth,BMF_CLEAR|BMF_INTERLEAVED,bitmap_sc);
-
- rport_ob.BitMap=bitmap_ob;
- rport_bg.BitMap=bitmap_bg;
-
- draw_thinborderfield(&rport_ob,c,0,1,w,h,FALSE);
-
- if (bitmap_ob && bitmap_bg)
- {
- while (TRUE)
- {
- // WaitBlit();
- ClipBlit(rport_wi,x2,y2,
- &rport_bg,0,1,w,h,ABNC|ABC);
-
- // WaitBlit();
- ClipBlit(&rport_ob,0,1,
- rport_wi,x2,y2,w,h,ABNC|ABC);
-
- do
- {
- WaitPort(window->UserPort);
- msg=(struct IntuiMessage*)GetMsg(window->UserPort);
- } while (!msg);
-
- x1 = x2;
- y1 = y2;
- x2 = msg->MouseX-w/2;
- y2 = msg->MouseY-h/2;
-
- clas = msg->Class;
- code = msg->Code;
-
- ReplyMsg((struct Message*)msg);
-
- // WaitBlit();
- ClipBlit(&rport_bg,0,1,
- rport_wi,x1,y1,w,h,ABNC|ABC);
-
- if (clas==IDCMP_MOUSEBUTTONS)
- {
- if (code == 0xe8)
- {
- (*x)=x1+w/2;
- (*y)=y1+h/2;
- break;
- }
- if (code == 0x69)
- {
- (*x)=-1;
- (*y)=-1;
- break;
- }
- }
- }
-
- tkFreeBitMap(bitmap_ob);
- tkFreeBitMap(bitmap_bg);
- }
- }
- // UnlockLayerInfo(&screen->LayerInfo);
-
- window->Flags&=~WFLG_RMBTRAP;
-
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_clear()
- {
- struct RastPort *rp=supercode_window->RPort;
- ULONG x=pal.x,y=pal.y,w=pal.w,h=pal.h;
-
- EraseRect(rp,x,y,x+w-1,y+h-1);
-
- x=field.x;
- y=field.y;
- w=field.w;
- h=field.h;
- EraseRect(rp,x,y,x+w-1,y+h-1);
-
- x=value.x;
- y=value.y;
- w=value.w;
- h=value.h;
- EraseRect(rp,x,y,x+w-1,y+h-1);
- }
- //-------------------------------------
- void supercode_drawpalette()
- {
- struct Window *win=supercode_window;
-
- LONG n=player1.num_colors;
- LONG x=pal.x,y=pal.y,w=pal.w,h=pal.h;
-
- LONG w1,wg,t;
-
- pal.max=n-1;
-
- w1=w/n;
- wg=w1*n;
-
- x+=(w-wg)/2;
-
- pal.xs=x;
- pal.w1=w1;
-
- for (t=1;t<=n;t++)
- {
- draw_thinborderfield(win->RPort,t,x,y,w1-2,h,0);
- x+=w1;
- }
-
-
- }
- //-------------------------------------
- void supercode_drawfield(BOOL drawlast)
- {
- struct GameEntry *entry=code_getlsttry(&player1);
- struct Window *win=supercode_window;
-
- LONG nx=player1.columns;
- LONG ny=player1.lines;
- LONG xf=field.x,y,wf=field.w,h=field.h;
- LONG xv=value.x,wv=value.w;
-
- LONG h1,t;
- LONG wf1,wfg,xf2;
- LONG wv1,wvg,xv2;
- LONG s=1,cf,cv;
- LONG border=0;
-
- field.max=nx-1;
-
- wf1=wf/nx;
- wfg=wf1*nx;
-
- wv1=wv/nx;
- wvg=wv1*nx;
-
- h1=wf1*2/3*Scrn.Ymul+2;
- h1=MAX(10,h1);
- h1=MIN(20,h1);
-
- y=field.y+field.h-h1;
-
- icon_w=wf1+2;
- icon_h=h1+2;
-
- xf+=(wf-wfg)/2;
- xv+=(wv-wvg)/2;
- xf2=xf;
- xv2=xv;
-
- field.xs=xf;
- field.w1=wf1;
- field.h1=value.h1=h1;
- value.xs=xv;
- value.w1=wv1;
-
- while (y>field.y)
- {
- xf=xf2;
- xv=xv2;
- if (entry)
- {
- for (t=0;t<nx;t++)
- {
- cf=code_getfield(&player1,entry,t);
- cv=code_getvalue(&player1,entry,t);
-
- if (code_getnexttry(entry)) border=1;
- else border=0;
-
- draw_thinborderfield(win->RPort,cf,xf,y,wf1-1,h1-3,border);
- if (player1.giveup && border==0 )
- {
- if (t==0)
- {
- EraseRect(win->RPort,xv,y,xv+wv-1,y+h1-1);
- }
- }
- else
- {
- draw_thinbordervalue(win->RPort,cv,xv,y,wv1-1,h1-3,border);
- }
- xf+=wf1;
- xv+=wv1;
- }
- }
- else
- {
- EraseRect(win->RPort,xf,y,xf+wfg-1,y+h1-1);
- EraseRect(win->RPort,xv,y,xv+wvg-1,y+h1-1);
- }
-
- y-=h1;
- s++;
-
- if (drawlast) break;
- if (entry) entry=code_getprevtry(entry);
-
- }
- if (!drawlast) SetGadgetAttrs(gadget_comb,supercode_window,0,GA_Integer,code_getpoints(&player1),TAG_END);
- }
- //-------------------------------------
- void supercode_drawall()
- {
- supercode_drawpalette();
- supercode_drawfield(FALSE);
- SetGadgetAttrs(gadget_name,supercode_window,0,GA_Text,prg_prefs->game.player_name,TAG_END);
- SetGadgetAttrs(gadget_name,supercode_window,0,GA_Text,prg_prefs->game.player_name,TAG_END);
- }
- //-------------------------------------
- void supercode_gfxmake()
- {
- struct Window *win=supercode_window;
- struct TextFont *font=Scrn.tkfont.font;
-
- if (win)
- {
- ULONG
- rx,ry,hb,
- bl,bt,br,bb,
- ys,
- w,h,hp,
- xg,yg,wg,hg,
- xp,yp,wp,
- xb,yb,wb,
- wb1;
-
- rx=4;
- ry=4;
- hb=font->tf_YSize+2*ry;
-
- bl=win->BorderLeft+rx;
- bt=win->BorderTop+ry+hb+ry;
- br=win->BorderRight+rx;
- bb=win->BorderBottom+ry;
-
- ys=win->BorderTop+ry;
-
- w=win->Width-bl-br;
- h=win->Height-bt-bb;
-
- hp=w/player1.num_colors*2/3;
- hp=MAX(16,hp);
- hp=MIN(25,hp);
-
- xg=bl;yg=bt;wg=w;hg=h-ry-hb-ry-hp;
- xp=bl;yp=bt+hg+ry;wp=w;
-
- xb=bl;yb=bt+hg+ry+hp+ry;wb=w;
-
- DrawBevelBox(win->RPort,xg,yg,wg,hg,
- GT_VisualInfo,Scrn.Visual,
- GTBB_FrameType,BBFT_RIDGE,
- GTBB_Recessed,TRUE,
- TAG_END);
-
- xg+=4+rx;
- yg+=2+ry;
- wg-=2*(4+rx);
- hg-=2*(2+ry);
-
- field.x=xg;
- field.y=yg;
- field.w=wg*2/3-rx;
- field.h=hg;
-
- value.x=xg+field.w+rx;
- value.y=yg;
- value.w=wg-field.w-rx;
- value.h=hg;
-
- wb1=wb/3;
-
- pal.x=xp+4;
- pal.y=yp+2;
- pal.w=wp-8;
- pal.h=hp-4;
-
- DrawBevelBox(win->RPort,xp,yp,wp,hp,
- GT_VisualInfo,Scrn.Visual,
- GTBB_FrameType,BBFT_BUTTON,
- GTBB_Recessed,TRUE,
- TAG_END);
-
- DrawBevelBox(win->RPort,field.x,field.y,field.w,field.h,
- GT_VisualInfo,Scrn.Visual,
- GTBB_FrameType,BBFT_BUTTON,
- GTBB_Recessed,TRUE,
- TAG_END);
- DrawBevelBox(win->RPort,value.x,value.y,value.w,value.h,
- GT_VisualInfo,Scrn.Visual,
- GTBB_FrameType,BBFT_BUTTON,
- GTBB_Recessed,TRUE,
- TAG_END);
-
- gadget_1st =
- gadget_new = NewObject (class_button,0,
- GA_Left,xb,
- GA_Top,yb,
- GA_Width,wb1-rx,
- GA_Height,hb,
- // GA_Previous,0,
- GA_RelVerify,TRUE,
- GA_Text,CatStr(TXT_WINGADNEW),
- GA_ID,ID_NEW,
- GA_Font,font,
- TAG_END);
-
- xb+=wb1;
- gadget_solve = NewObject (class_button,0,
- GA_Previous,gadget_new,
- GA_Left,xb,
- GA_Top,yb,
- GA_Width,wb1,
- GA_Height,hb,
- GA_RelVerify,TRUE,
- GA_Text,CatStr(TXT_WINGADGIVEUP),
- GA_ID,ID_SOLVE,
- GA_Font,font,
- TAG_END);
-
- xb+=wb1+rx;
- gadget_score = NewObject (class_button,0,
- GA_Previous,gadget_solve,
- GA_Left,xb,
- GA_Top,yb,
- GA_Width,wb1-rx,
- GA_Height,hb,
- GA_RelVerify,TRUE,
- GA_Text,CatStr(TXT_WINGADHIGHSCORE),
- GA_ID,ID_SCORE,
- GA_Font,font,
- TAG_END);
-
- xb=bl;
- wb1=wb/4;
- gadget_name = NewObject (class_text,0,
- GA_Previous,gadget_score,
- GA_Left,xb,
- GA_Top,ys,
- GA_Width,wb1*2-rx,
- GA_Height,hb,
- GA_Text,prg_prefs->game.player_name,
- GA_TextJust,BOX_CENTER,
- GA_Font,font,
- TAG_END);
-
- xb+=wb1*2;
- gadget_comb = NewObject (class_text,0,
- GA_Previous,gadget_name,
- GA_Left,xb,
- GA_Top,ys,
- GA_Width,wb1,
- GA_Height,hb,
- GA_Integer,code_getpoints(&player1),
- GA_TextJust,BOX_CENTER,
- GA_Font,font,
- TAG_END);
-
- xb+=wb1+rx;
- gadget_time = NewObject (class_text,0,
- GA_Previous,gadget_comb,
- GA_Left,xb,
- GA_Top,ys,
- GA_Width,wb1-rx,
- GA_Height,hb,
- GA_Text,0,
- GA_TextJust,BOX_CENTER,
- GA_Font,font,
- TAG_END);
-
- field.x+=2+2;
- field.y+=1+1;
- field.w-=4+4;
- field.h-=2+2;
-
- value.x+=2+2;
- value.y+=1+1;
- value.w-=4+4;
- value.h-=2+2;
-
- supercode_drawall();
-
- AddGList(win,gadget_new,-1,-1,0);
- RefreshGList(gadget_new,win,0,-1);
- }
- }
- //-------------------------------------
- void supercode_gfxclr()
- {
- #define DisposeGadget(g) if (g) DisposeObject(g);
- struct Window *win=supercode_window;
-
- RemoveGList(win,gadget_1st,-1);
-
- DisposeGadget(gadget_new);
- DisposeGadget(gadget_solve);
- DisposeGadget(gadget_score);
- DisposeGadget(gadget_name);
- DisposeGadget(gadget_comb);
- DisposeGadget(gadget_time);
-
- RefreshWindowFrame(win);
- EraseRect(win->RPort,win->BorderLeft,win->BorderTop,win->Width-win->BorderRight-1,win->Height-win->BorderBottom-1);
-
- supercode_gfxmake();
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_inputname()
- {
- struct Window *supercode_name;
- struct Requester req;
- LONG h=30;
-
- InitRequester(&req);
-
- req.LeftEdge=-1;
- req.TopEdge=-1;
- req.Width=1;
- req.Height=1;
-
- Request(&req,supercode_window);
-
- supercode_name=OpenWindowTags(0,
- WA_Title,CatStr(TXT_WINTITLENAME),
- WA_Left,supercode_window->LeftEdge,
- WA_Top,supercode_window->TopEdge + supercode_window->BorderTop,
- WA_Width,supercode_window->Width,
- WA_InnerHeight,h,
- (Scrn.Scrn && Scrn.FlgPublic==FALSE) ? WA_CustomScreen : WA_PubScreen,Scrn.Scrn,
- WA_Flags,
- WFLG_ACTIVATE|
- WFLG_CLOSEGADGET|
- WFLG_DRAGBAR|
- WFLG_DEPTHGADGET|
- WFLG_NEWLOOKMENUS|
- 0,
- WA_IDCMP,
- IDCMP_GADGETUP|
- IDCMP_CLOSEWINDOW|
- 0,
- WA_AutoAdjust,TRUE,
- TAG_END);
-
- if (supercode_name)
- {
- struct Window *win=supercode_name;
- struct Gadget *gad_name;
- struct IntuiMessage *msg;
-
- struct Gadget *gadg;
- LONG clas;
- LONG ready=FALSE;
- APTR border;
- LONG w=win->Width-win->BorderLeft-win->BorderRight;
- LONG x=win->BorderLeft;
- LONG y=win->BorderTop;
-
- h-=8;
- x+=6;w-=8;
- y+=5;
- border = NewObject(0,FRAMEICLASS,
- IA_Left,-4,
- IA_Top,-2,
- IA_Width,w,
- IA_Height,h,
- IA_FrameType,FRAME_RIDGE,
- TAG_END);
- w-=8;
- h-=4;
- gad_name = NewObject (0,STRGCLASS,
- GA_Image,border,
- // GA_Previous,0,
- GA_Left,x,
- GA_Top,y,
- GA_Width,w,
- GA_Height,h,
- GA_RelVerify,TRUE,
- STRINGA_Buffer,prg_prefs->game.player_name,
- STRINGA_MaxChars,MAX_PLAYERNAME,
- STRINGA_BufferPos,0,
- STRINGA_DispPos,0,
- STRINGA_Justification,GACT_STRINGCENTER,
- TAG_END);
-
- AddGList(win,gad_name,-1,-1,0);
- RefreshGList(gad_name,win,0,-1);
- ActivateGadget(gad_name,win,0);
-
- while (!ready)
- {
- WaitPort(win->UserPort);
- msg=(struct IntuiMessage*)GetMsg(win->UserPort);
-
- gadg = (APTR)msg->IAddress;
- clas = msg->Class;
-
- ReplyMsg((struct Message*)msg);
-
- switch (clas)
- {
- case IDCMP_CLOSEWINDOW:
- ready=TRUE;
- break;
- case IDCMP_GADGETUP:
- ready=TRUE;
- break;
- }
- }
- RemoveGList(win,gad_name,-1);
-
- if (gad_name) DisposeObject(gad_name);
- if (border) DisposeObject(border);
-
- CloseWindow(supercode_name);
- }
- EndRequest(&req,supercode_window);
-
- SetGadgetAttrs(gadget_name,supercode_window,0,GA_Text,prg_prefs->game.player_name,TAG_END);
- // RefreshGList(gadget_name,supercode_window,0,1);
-
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_compare()
- {
- if (!player1.finish)
- {
- code_comparelast(&player1);
- supercode_drawfield(FALSE);
-
- if (player1.finish)
- {
- score_add(&player1,prg_prefs->game.player_name);
- }
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_createtable()
- {
- ULONG t,a=0,b=0;
- ULONG n=player1.num_colors;
- BOOL m;
-
- Memory_Free((UBYTE**)&color_tabl);
- Memory_Free(&color_stat);
- color_tabl=(UWORD*)Memory_Alloc(n*2+2);
- color_stat=Memory_Alloc(n+2);
-
- color_tabl[0]=0;
-
- a=0;
- b=0;
- m=FALSE;
- for(t=1;t<=n;t++)
- {
- if (m)
- {
- if (Reg_Col[a]==0xffff)
- {
- b++;
- if (Reg_Col[b]==0xffff) break;
- a=b+1;
- if (Reg_Col[a]==0xffff) break;
- }
- }
- else
- {
- b=a;
- if (Reg_Col[a]==0xffff)
- {
- m=TRUE;
- a=1;
- b=0;
- }
- }
-
- color_tabl[t] = Reg_Col[a] << 8 | Reg_Col[b];
- color_stat[t] = 0;
-
- a++;
- }
- if (display_mode==DISPLAY_COLORS)
- if (t<=n) display_mode=DISPLAY_LETTER;
- }
- //-------------------------------------
-
- ULONG last_sec,last_mic;
- ULONG frst_sec,frst_mic;
-
- //-------------------------------------
- void supercode_newgame()
- {
- struct Window *win=supercode_window;
- long min_width1;
- long min_width2;
- long width=win->Width;
-
- code_newcomb(&player1);
- supercode_createtable();
- min_width1=win->BorderLeft+4+4+6+player1.columns*7+4+4+4+player1.columns*7+6+4+4+win->BorderRight;
- min_width2=win->BorderLeft+4+4+6+player1.num_colors*10+6+4+4+win->BorderRight;
- width=MAX(min_width1,min_width2);
-
- if ( win->Width < width )
- {
- SizeWindow(win,width-win->Width,0);
- WindowLimits(win,width,0,0,0);
- }
- else
- {
- WindowLimits(win,width,0,0,0);
- supercode_clear();
- supercode_drawall();
- }
- if (gadget_time) SetGadgetAttrs(gadget_time,supercode_window,0,GA_Text,"0:00:00",TAG_END);
- }
- //-------------------------------------
- void supercode_newplayer()
- {
- supercode_inputname();
- supercode_newgame();
- }
- //-------------------------------------
- void supercode_giveup()
- {
- code_giveup(&player1);
- supercode_drawfield(TRUE);
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_dogadget(ULONG id,ULONG qual)
- {
- switch (id)
- {
- case ID_NEW:
- if (qual & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
- {
- supercode_newplayer();
- }
- {
- supercode_newgame();
- }
- break;
- case ID_SCORE:
- score_display();
- break;
- case ID_SOLVE:
- supercode_giveup();
- break;
- case ID_COMP:
- supercode_compare();
- break;
- }
- }
- //-------------------------------------
- BOOL in_range(ULONG mx,ULONG my,struct box *box)
- {
- ULONG x=box->x;
- ULONG y=box->y;
- ULONG w=box->w;
- ULONG h=box->h;
- ULONG xe=x+w-1;
- ULONG ye=y+h-1;
- ULONG res=FALSE;
-
- if ( mx >= x && mx <=xe )
- if ( my >= y && my <=ye ) res=TRUE;
-
- return res;
- }
- //-------------------------------------
- void supercode_mouseclick(ULONG code,ULONG qual,ULONG x,ULONG y)
- {
- LONG p=0;
- LONG col=0;
-
- if (!player1.finish)
- {
- if (code == 0x68) ModifyIDCMP(supercode_window,supercode_window->IDCMPFlags | IDCMP_MOUSEMOVE);
- if (code == 0xE8) ModifyIDCMP(supercode_window,supercode_window->IDCMPFlags & ~IDCMP_MOUSEMOVE);
-
- if (in_range(x,y,&field))
- {
- LONG px,py;
-
- px=(x-field.xs)/field.w1;
- py=(field.y+field.h-y)/field.h1;
-
- if (px<0) px=0;
- if (px>field.max) px=field.max;
-
- if (code == 0x68)
- {
- col=code_getfield(&player1,code_getnumtry(&player1,player1.lines-py),px);
- }
- }
- if (in_range(x,y,&pal))
- {
- p=(x-pal.xs)/pal.w1;
-
- if (p<0) p=0;
- if (p>pal.max) p=pal.max;
-
- if (code == 0x68)
- {
- if (qual & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
- {
- color_stat[p+1]++;
- if (color_stat[p+1]>=STATUS_END) color_stat[p+1]=0;
- supercode_drawall();
- }
- else
- {
- col=p+1;
- }
- }
- }
- else if (in_range(x,y,&value))
- {
- if (code == 0xE8) supercode_dogadget(ID_COMP,qual);
- }
-
- if (col)
- {
- icon_drag(col,&x,&y);
-
- if (in_range(x,y,&field))
- {
- x-=field.xs;
- y-=field.y;
- p=x/field.w1;
-
- if (p<0) p=0;
- if (p>field.max) p=field.max;
-
- code_set(&player1,p,col);
- supercode_drawfield(TRUE);
- }
- }
-
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_time(ULONG sec,ULONG mic)
- {
- ULONG t=sec - player1.sec_start;
-
- if ((player1.started) && (!player1.finish) && (sec - last_sec)!=0)
- {
- ULONG h=(t/3600);
- ULONG m=(t-h*3600)/60;
- ULONG s=(t-m*60+h*3600);
- UBYTE timestr[10];
-
- sprintf(timestr,"%2.2d:%02.2d:%02.2d",h,m,s);
-
- SetGadgetAttrs(gadget_time,supercode_window,0,GA_Text,timestr,TAG_END)
- }
- last_sec=sec;
- last_mic=mic;
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_about()
- {
- display_error(TXT_ABOUT,ASK_OK,supercode_version,programmer_name,__DATE2__,prg_prefs->game.player_name);
- }
- //-------------------------------------
-
-
- //-------------------------------------
- LONG supercode_getbit()
- {
- LONG bit=0;
-
- if (supercode_window)
- {
- bit=1 << supercode_window->UserPort->mp_SigBit;
- }
-
- return bit;
- }
- //-------------------------------------
- VOID supercode_domsg()
- {
- struct Window *win=supercode_window;
- struct IntuiMessage *msg;
-
- struct Gadget *gadg;
- LONG clas;
- LONG code;
- LONG qual;
- LONG posx,posy,seco,micr;
-
- while ((msg=(struct IntuiMessage*)GetMsg(win->UserPort)))
- {
- gadg = (APTR)msg->IAddress;
- clas = msg->Class;
- code = msg->Code;
- qual = msg->Qualifier;
- posx = msg->MouseX;
- posy = msg->MouseY;
- seco = msg->Seconds;
- micr = msg->Micros;
-
- ReplyMsg((struct Message*)msg);
-
- switch (clas)
- {
- case IDCMP_INTUITICKS:
- supercode_time(seco,micr);
- break;
- case IDCMP_CHANGEWINDOW:
- // supercode_StoreSize(MsgBlk);
- break;
- case IDCMP_RAWKEY:
- break;
- case IDCMP_SIZEVERIFY:
- break;
- case IDCMP_NEWSIZE:
- supercode_gfxclr();
- break;
- case IDCMP_MENUPICK:
- Command_Menu(Menu_Main.Menu,code);
- break;
- case IDCMP_CLOSEWINDOW:
- Quit();
- break;
- case IDCMP_MOUSEMOVE:
- case IDCMP_MOUSEBUTTONS:
- supercode_mouseclick(code,qual,posx,posy);
- break;
- case IDCMP_GADGETDOWN:
- case IDCMP_GADGETUP:
- supercode_dogadget(gadg->GadgetID,qual);
- break;
- case IDCMP_INACTIVEWINDOW:
- break;
- }
- }
- }
- //-------------------------------------
-
- #define SAVEGAMEHEAD 'SAVE'
- #define VIEWGAMEHEAD 'VIEW'
- #define GAMECLR 'CLR '
- #define GAMESTAT 'STAT'
-
- #define PLYNAME 'NAME'
- //-------------------------------------
- void supercode_savegame()
- {
- struct Field *player=&player1;
- struct GameEntry *entry=code_getcombi(player);
- struct tkfile *file;
-
- if (prefs_askfile(CatStr(TXT_SAVEGAMESAVE),prg_prefs->game.save_file,FILENAME_MAX,TRUE))
- {
- ULONG s,m;
-
- file = file_open(prg_prefs->game.save_file,MODE_NEWFILE,TRUE);
-
- if (file->file)
- {
- if (player->finish)
- {
- file_writelong(file,VIEWGAMEHEAD);
- }
- else
- {
- file_writelong(file,SAVEGAMEHEAD);
- }
-
- file_saveblock(file,PLYNAME,0,MAX_PLAYERNAME,prg_prefs->game.player_name);
-
- CurrentTime(&s,&m);
- m=player->sec_start;
- player->sec_start=s-player->sec_start;
-
- file_saveblock(file,GAMEPLAYER,VERGAMEPLAYER,sizeof(struct Field),player);
- file_saveblock(file,GAMEENTRY,VERGAMEENTRY,entry->size,entry);
-
- entry=code_get1sttry(player);
- while(entry)
- {
- file_saveblock(file,GAMEENTRY,VERGAMEENTRY,entry->size,entry);
- entry=code_getnexttry(entry);
- }
- file_saveblock(file,GAMESTAT,0,player->num_colors,color_stat);
-
- if (file->ok && !player->finish)
- {
- supercode_newgame();
- }
- }
- file_free(&file);
- }
- }
- //-------------------------------------
- void supercode_loadgame()
- {
- struct Field *player=&player1;
- struct tkfile *file;
- ULONG c=0;
- BOOL load=TRUE;
- ULONG ind=0;
- struct GameEntry *new;
-
-
- if (prefs_askfile(CatStr(TXT_SAVEGAMELOAD),prg_prefs->game.save_file,FILENAME_MAX,FALSE))
- {
- file = file_open(prg_prefs->game.save_file,0,0);
- ind=file_readlong(file);
-
- if (ind==SAVEGAMEHEAD || ind==VIEWGAMEHEAD)
- {
- if (ind==VIEWGAMEHEAD || (ASK_OK==(display_error(TXT_ASKFORFILECLEAR,ASK_OK|ASK_ABORT))))
- {
- code_freefield(player);
-
- while (load)
- {
- ind=file_readlong(file);
-
- switch(ind)
- {
- case PLYNAME:
- file_loadblock(file,0,MAX_PLAYERNAME,prg_prefs->game.player_name);
- break;
- case GAMEPLAYER:
- c=1;
- file_loadblock(file,VERGAMEPLAYER,sizeof(struct Field),player);
- List_Init(&player->try,NT_TRY,0);
- supercode_createtable();
- break;
- case GAMESTAT:
- if (c)
- {
- file_loadblock(file,0,player->num_colors,color_stat);
- }
- break;
- case GAMEENTRY:
- if (c)
- {
- LONG size=sizeof(struct GameEntry)+2*player->columns;
-
- c++;
- new=(struct GameEntry*)Memory_Alloc(size);
- file_loadblock(file,VERGAMEENTRY,size,new);
-
- new->field=((UBYTE*)new)+sizeof(struct GameEntry);
- new->value=((UBYTE*)new)+sizeof(struct GameEntry)+player->columns;
-
- List_AddTail(&player->try,&new->node);
- }
- break;
- case GAMECLR:
- default:
- load=FALSE;
- break;
- }
- }
- }
- }
- file_free(&file);
-
- if (c)
- {
- ULONG s,m;
- CurrentTime(&s,&m);
- player->sec_start=s-player->sec_start;
-
- supercode_drawall();
-
- if (!player->finish)
- {
- file = file_open(prg_prefs->game.save_file,MODE_NEWFILE,0);
- file_writelong(file,GAMECLR);
- file_free(&file);
- file_delete(prg_prefs->game.save_file);
- }
- }
-
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_open()
- {
- supercode_window=OpenWindowTags(0,
- WA_Title,CatStr(TXT_WINTITLE),
-
- WA_Left,prg_prefs->win.game.Xpos,
- WA_Top,prg_prefs->win.game.Ypos,
- WA_Width,prg_prefs->win.game.WinW,
- WA_Height,prg_prefs->win.game.WinH,
- (Scrn.Scrn && Scrn.FlgPublic==FALSE) ? WA_CustomScreen : WA_PubScreen,Scrn.Scrn,
- WA_Flags,
- WFLG_ACTIVATE|
- WFLG_CLOSEGADGET|
- WFLG_DRAGBAR|
- WFLG_DEPTHGADGET|
- WFLG_NEWLOOKMENUS|
- // WFLG_NOCAREREFRESH entspricht dem Tag WA_NoCareRefresh;
- WFLG_REPORTMOUSE|
- // WFLG_RMBTRAP entspricht dem Tag WA_RMBTrap;
- // WFLG_SIMPLE_REFRESH entspricht dem Tag WA_SimpleRefresh;
- WFLG_SIZEBBOTTOM|
- // WFLG_SIZEBRIGHT entspricht dem Tag WA_SizeBRight;
- WFLG_SIZEGADGET|
- // WFLG_SMART_REFRESH entspricht dem Tag WA_SmartRefresh;
- 0,
- WA_IDCMP,
- IDCMP_MOUSEBUTTONS|
- // IDCMP_MOUSEMOVE|
- IDCMP_GADGETDOWN|
- IDCMP_GADGETUP|
- IDCMP_CLOSEWINDOW|
- IDCMP_NEWSIZE|
- IDCMP_MENUPICK|
- IDCMP_INTUITICKS|
- 0,
- // WA_Zoom,0,
- WA_AutoAdjust,TRUE,
- WA_MaxWidth,-1,
- WA_MaxHeight,-1,
- WA_MinWidth,100,
- WA_MinHeight,100,
- TAG_END);
-
- SetMenuStrip(supercode_window,Menu_Main.Menu);
-
- supercode_gfxmake();
-
- }
- //-------------------------------------
- void supercode_close()
- {
- if (supercode_window)
- {
- window_close(supercode_window,&prg_prefs->win.game);
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void supercode_init()
- {
- supercode_createtable();
- InitRastPort(&rport_ob);
- InitRastPort(&rport_bg);
-
- }
- //-------------------------------------
- void supercode_free()
- {
- Memory_Free((UBYTE**)&color_tabl);
- Memory_Free(&color_stat);
- supercode_close();
- }
- //-------------------------------------
-
-